package table_bank

import (
	"time"

	"gitee.com/klein-x/biz/model/mysql/table"
	"gitee.com/klein-x/biz/module/db/mysql"
	"gorm.io/gorm"
)

type BankQuestion struct {
	QuestionID    string         `gorm:"primaryKey;type:char(36);unique;not null;comment:'题目ID'"`
	QuestionType  string         `gorm:"type:char(1);not null;comment:'题目类型, 1单选,2多选,3判断'"`
	BackgroundID  *string        `gorm:"type:char(36);comment:'题目背景ID'"`
	QuestionText  string         `gorm:"type:text;comment:'题目文本'"`
	OptionText    string         `gorm:"type:text;comment:'选项文本'"`
	CorrectAnswer []string       `gorm:"type:text;serializer:json;comment:'正确答案'"`
	Explanation   string         `gorm:"type:text;comment:'题目解释'"`
	CreatedAt     time.Time      `gorm:"comment:'创建时间'"`
	UpdatedAt     time.Time      `gorm:"comment:'更新时间'"`
	DeletedAt     gorm.DeletedAt `gorm:"comment:'软删除时间'"`
}

func (bq *BankQuestion) TableName() string {
	return "bank_questions"
}

func QuestionGetByKey(key string) (*BankQuestion, error) {
	db := mysql.GetGlobalDB()
	var question BankQuestion
	return table.SelectCheck(&question, db.Where("question_id = ?", key).First(&question))
}
